<script>
	$(function(){
		<php>
			if ($_field['config']['queryparams']) {
				$_where = '';
				$_queryparams = explode("\r\n",$_field['config']['queryparams']);
				foreach ($_queryparams as $key => $value) {
					$_tmp = explode('|',$value);
					if (stripos($_tmp[2],'(I)') === 0) {
						$_tmp[2] = I(substr($_tmp[2],3));
					}elseif(stripos($_tmp[2],'($)') === 0){
						$_tmp[2] = $_fields[substr($_tmp[2],3)]['_value'];
					};
					$_where .= $_tmp[0].":['".$_tmp[1]."','".$_tmp[2]."'],";
				}
			};
		</php>
		EBCMS.CORE.api({
			<eq name='_field.config.group' value='1'>
			group:'group',
			<else/>
				<eq name='_field.config.tree' value='1'>
				tree:'tree',
				</eq>
				<eq name='_field.config.rootitem' value='1'>
				rootitem:true,
				</eq>
			</eq>
			queryParams:{
				sort:'sort',
				order:'desc',
				__model:'{$_field.config.model}',
				<notempty name="_field.config.queryparams">
				__where:{
					{$_where}
				},
				</notempty>
			},
			loadAfter:function(data){
				$select = $('#{$_ns}');
				var str = EBCMS.FN.renderSelect(data['rows'],'{$_field._value}','{$_field.config.valuefield|default="id"}','{$_field.config.textfield|default="title"}');
				$select.append(str);
			}
		});
	});
</script>
<eq name='_field.config.editable' value='1'>
	<div class="row">
		<div class="col-md-8">
			<input type="text" class="form-control" id="{$_ns}_obj" name="{$_field._field}" value="{$_field._value}" placeholder="{$_field.config.prompt|default=''}" <eq name='_field.config.readonly' value='1'>readonly</eq> <eq name='_field.config.disabled' value='1'>disabled</eq> <eq name='_field.config.required' value='1'>required</eq>>
		</div>
		<div class="col-md-4">
			<select class="form-control" id="{$_ns}" onchange="$('#{$_ns}_obj').val($(this).val());" <eq name='_field.config.readonly' value='1'>readonly</eq> <eq name='_field.config.disabled' value='1'>disabled</eq> <eq name='_field.config.required' value='1'>required</eq>>
			</select>
		</div>
	</div>
<else/>
	<select class="form-control" id="{$_ns}" name="{$_field._field}" <eq name='_field.config.readonly' value='1'>readonly</eq> <eq name='_field.config.disabled' value='1'>disabled</eq> <eq name='_field.config.required' value='1'>required</eq>>
	</select>
</eq>